// GoConnectToMysql.go

package main;

import (
  "database/sql"
  "fmt"
  _"github.com/go-sql-driver/mysql"
)

func main() {
	db, err := sql.Open("mysql", "go4th:go4th@tcp(127.0.0.1:3306)/go4th?charset=utf8");
	if(err != nil) {
		fmt.Println("Connect MySQL fail [%s]", err);
	} else {
		fmt.Println("Connect MySQL success! ");
	}

	// insert
	r, insertErr := db.Exec("insert into geek_go(id, name, nick_name, address) values (1003, 'Name 1003', 'NickName 1003', 'Address 1003') ");
	fmt.Println("insertErr:", insertErr, r);
	fmt.Println("finish insert");



	// query
	row := db.QueryRow("select count(*) as num from geek_go");
	var count int;
	row.Scan(&count)
	fmt.Println("queryNum: ", count);

	db.Exec("delete from geek_go where id = 1003 ");

}